package com.wei.duowan.bbs.ui.adapter;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.wei.duowan.bbs.model.NewsChannelBean;
import com.wei.duowan.bbs.ui.fragment.NewsListFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：赵若位
 * 时间：2019/9/3 14:14
 * 联系方式：1070138445
 * 功能：
 */
public class NewsTitleAdapter extends FragmentStatePagerAdapter
{
    private List<NewsChannelBean> mList;


    public NewsTitleAdapter(FragmentManager fm)
    {
        super(fm);
        mList = new ArrayList<>();
    }

    public void setNewData(@Nullable List<NewsChannelBean> list)
    {
        mList.clear();
        mList.addAll(list == null ? new ArrayList<>() : list);
        notifyDataSetChanged();
    }


    @Override
    public Fragment getItem(int position)
    {
        return NewsListFragment.getFragment(mList.get(position));
    }


    @Override
    public int getCount()
    {
        return mList.size();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position)
    {
        return mList.get(position).getName();
    }

}
